home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / milliped.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  2KB  |  65 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12. /*
  13.  * This wrapper routine is necessary because Millipede requires a direction bit
  14.  * to be set or cleared. The direction bit is held until the mouse is moved
  15.  * again. We still don't understand why the difference between
  16.  * two consecutive reads must not exceed 7. After all, the input is 4 bits
  17.  * wide, and we have a fifth bit for the sign...
  18.  *
  19.  * The other reason it is necessary is that Millipede uses the same address to
  20.  * read the dipswitches.
  21.  */
  22.  
  23. static int dsw_select;
  24.  
  25. WRITE_HANDLER( milliped_input_select_w )
  26. {
  27.     dsw_select = (data == 0);
  28. }
  29.  
  30. READ_HANDLER( milliped_IN0_r )
  31. {
  32.     static int oldpos,sign;
  33.     int newpos;
  34.  
  35.     if (dsw_select)
  36.         return (readinputport(0) | sign);
  37.  
  38.     newpos = readinputport(6);
  39.     if (newpos != oldpos)
  40.     {
  41.         sign = (newpos - oldpos) & 0x80;
  42.         oldpos = newpos;
  43.     }
  44.  
  45.     return ((readinputport(0) & 0x70) | (oldpos & 0x0f) | sign );
  46. }
  47.  
  48. READ_HANDLER( milliped_IN1_r )
  49. {
  50.     static int oldpos,sign;
  51.     int newpos;
  52.  
  53.     if (dsw_select)
  54.         return (readinputport(1) | sign);
  55.  
  56.     newpos = readinputport(7);
  57.     if (newpos != oldpos)
  58.     {
  59.         sign = (newpos - oldpos) & 0x80;
  60.         oldpos = newpos;
  61.     }
  62.  
  63.     return ((readinputport(1) & 0x70) | (oldpos & 0x0f) | sign );
  64. }
  65.